<?php
get_header();
require(WEBTREATS_INCLUDES . "/var.php");

$post_obj = $wp_query->get_queried_object();
$post_ID = $post_obj->ID;

$show_on_front = get_option('show_on_front');
$page_on_front = get_option('page_on_front');
$page_for_posts = get_option('page_for_posts');


if( ($show_on_front == 'page') && ($page_on_front == $blog_page) || ($show_on_front == 'page') && ($page_for_posts == $post_ID) ) {
	return require(WEBTREATS_INCLUDES . "/template-blog.php");
}else{

?>

<div id="body_block" <?php webtreats_body_class(); ?>>
		
	<?php if(!$home_slider_disable) { webtreats_header_slider_switcher($homepage_slider); } ?>
			
	<?php if(!$home_teaser_disable) : ?>
		<div id="intro_blurb">
			<div class="inner">	

			
			<?php if(!$action_button_disable) : ?>
				<?php $teaser_link = '#';
					if($teaser_button == 'page' && $teaser_button_page){
						  $teaser_link = get_permalink($teaser_button_page);
				    }else{
						if($teaser_button == 'custom' && $teaser_button_custom){
							  $teaser_link = $teaser_button_custom;
						}
					}
				?>
				<a class="button_link alignright large_button" href="<?php echo $teaser_link; ?>"><span><?php echo stripslashes($teaser_button_text); ?></span></a>

			<?php endif; ?>
				<h3 style="margin-bottom:0">
			   		<?php $homepage_teaser_text = stripslashes($homepage_teaser_text); echo do_shortcode($homepage_teaser_text); ?>
				</h3><!-- blurb -->
			</div><!-- inner -->
		</div><!-- intro_blurb -->
	<?php endif; ?>
	<div id="body_block_background">
		
	<div class="inner">
		<div id="main">
			<div class="content">			
						
		<?php
		//homepage content editor
		$content = stripslashes($content); $content = do_shortcode($content); $content = apply_filters('the_content', $content);
		echo $content;
			
		//mainpage content area import			
		global $more;
		if($mainpage_content && $mainpage_content != $blog_page){
			$maincontent = $mainpage_content;
			$maincontent = "showposts=1&page_id=$maincontent";
			query_posts($maincontent);

			if (have_posts()) : 
			while (have_posts()) : the_post();
			$more = 0; ?>
				
			<?php the_content("<span>Read More</span>",false);

			endwhile; endif;
		}
				
		//blog posts	
		if( ($mainpage_content) && ($mainpage_content == $blog_page) || ($frontpage_blog) ) :
			$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
			$exclude_blog_cats = preg_replace("!(\d)+!","-${0}$0", $blog_excludecats);
			$query_string = "cat=".$exclude_blog_cats."&paged=$paged";
			query_posts($query_string);
			$counter=0; ?>

		<?php if(have_posts()) : while(have_posts()) : the_post(); ?>

		<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
			<div class="blog_module">

				<?php webtreats_post_image(); ?>

				<h2 class="blog_header">
					<a href="<?php echo get_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a>
					<span class="comment_bubble"><?php comments_popup_link('0', '1', '%'); ?></span>
				</h2>		

				<div class="entry">
					<?php
					if ($custom_use_more_quicktag) {
						$more = 0;
						the_content("<span>Read More</span>",false);
					}else{ 
						the_excerpt(); ?><a style="position:relative;top:-10px;" class="fancy_link" href="<?php the_permalink(); ?>">Read More &raquo;</a>
					<?php } ?>
				</div>

				<div class="blog_meta">
					<?php $get_year = get_the_time('Y'); $get_month = get_the_time('m'); ?>
					Posted on: <a href="<?php echo get_month_link($get_year, $get_month); ?>"><?php the_time('m-j-Y') ?></a><br />
					Posted in: <?php the_category(', ') ?>
				</div>

			</div><!-- blog_module -->
		</div><!-- post -->

			<?php endwhile; ?>

			<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>

			<?php else : ?>

				<p>Sorry, that document can not be found.</p>

			<?php endif; endif;?>
							
		</div><!--  content -->
	 </div> <!-- main -->
	
	<?php if(is_active_sidebar(2)) : ?>
		<div id="sidebar">
			<div class="content">
				<?php dynamic_sidebar(2); ?>
			</div><!-- content -->
			<div id="sidebar_bottom"></div>
		</div><!-- sidebar -->
	<?php endif; ?>
	
<?php get_footer(); } ?>